Support for non-CL Clang on Windows#981
Conversation
Clang on Windows defines _MSC_VER, but it doesn't understand _Printf_format_string_
It doesn't generate separate Debug and Release directories and instead puts the executable directly under build/
bnoordhuis
left a comment
There was a problem hiding this comment.
Mostly LGTM but I believe @saghul reviewed this the first time around so he's likely more qualified to sign off on it.
CMakeLists.txt
Outdated
| if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32) | ||
| add_compile_definitions(_CRT_SECURE_NO_WARNINGS) | ||
| add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) | ||
| endif() |
There was a problem hiding this comment.
| if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32) | |
| add_compile_definitions(_CRT_SECURE_NO_WARNINGS) | |
| add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) | |
| endif() | |
| if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32) | |
| add_compile_definitions(_CRT_SECURE_NO_WARNINGS) | |
| add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) | |
| endif() |
There was a problem hiding this comment.
this did not seem to be there or working if the branch was current yesterday. I had to manual #define and also "#pragma warning(disable : 4996)" in several files for MS Clang to compile.
There was a problem hiding this comment.
forget my comment ... I upgraded and compile now with msbuild and the problem is fixed.
| } | ||
|
|
||
| #ifdef __GNUC__ | ||
| #if defined(__GNUC__) || defined(__clang__) |
There was a problem hiding this comment.
Doesn't clang-on-windows define __GNUC__? Because clang-on-linux definitely does:
$ clang -E -dM - < /dev/null | grep GNUC
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 4
There was a problem hiding this comment.
I believe it does too. What are you trying to fix here @HJfod ?
.github/workflows/ci.yml
Outdated
| cl.exe /DJS_NAN_BOXING=1 /Zs cxxtest.cc | ||
|
|
||
| windows-clang: | ||
| windows-ninja-clang: |
There was a problem hiding this comment.
Nit, can we call this windows-real-clang perhaps?
CMakeLists.txt
Outdated
|
|
||
| # Clang on Windows without MSVC command line fails because the codebase uses | ||
| # functions like strcpy over strcpy_s | ||
| if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND WIN32) |
There was a problem hiding this comment.
Don't you also want to add NOT MSVC here, so make sure it's not ClangCL ?
CMakeLists.txt
Outdated
| if(MSVC) | ||
| set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8388608") | ||
| else() | ||
| elseif(MINGW) |
There was a problem hiding this comment.
Why do you want to skip this on Clang?
There was a problem hiding this comment.
Clang didn't seem to understand the parameter syntax and I couldn't find an equivalent option. Can take another look 👍
There was a problem hiding this comment.
--stack_size
Clang in MS environment doesn't have a clang-gcc program, it has a clang-cpp program. no it's not GCC. In fact It does not carry the MSVC flag, it carries the WIN32 flag but MSYS2 Clang carries WIN32 as well. I don't think there's a special flag.
so what I did was if (msvc) elseif (GNU) else () .. doesn't seem to see Clang on my end!
Correction:. Clang knows nothing about GCC or GNU. in MSYS2 Clang responds to MINGW.
There may be something intermittent about how Clang responds to flags. I ended up reinstalling my build systems more than once, trying to reproduce a bug; if Ninja is installed a certain way in MSYS2 (the way that WinLibs does it). I verified that Clang will lose the WIN32 flag.
There was a problem hiding this comment.
I was wrong. --stack_size is clang on mac. there's no stack size in MS version and I don't think there is in linux. What it does do is ignore the flag --stack_size and not --stack, and I get 140 warnings and don't see it.
oh and just fyi .. I reinstalled my build environments for clang and the flags completely change between ninja, make, and msbuild. so that section acts differently. I've seen 4 different flagsets today. but I have no 'Clang' flag in MSYS or MSVC. Clang in the MINGW environment gives no WIN32 flag. if someone uses WinLibs, I bet this flag isn't even there.
| } | ||
|
|
||
| #ifdef __GNUC__ | ||
| #if defined(__GNUC__) || defined(__clang__) |
There was a problem hiding this comment.
I believe it does too. What are you trying to fix here @HJfod ?
getopt_compat.h
Outdated
| #include <stdarg.h> | ||
| #include <stdio.h> | ||
| #include <windows.h> | ||
| /* Required for JS_PRINTF_FORMAT */ |
There was a problem hiding this comment.
Can we not do this and silence the warnings if need be? I actually want to get rid of this header altogether by parsing command line arguments by hand in qjsc, since it's only used there...
* CI action renamed to just `windows-clang` * Remove inclusion of `cutils.h` from `getopt_compat.h` and just suppress format string literal warnings * Add more comments to `quickjs-libc.c` and `quickjs.h` * Update `CMakeLists.txt` to also set 8 MB stack size for Windows Clang
|
Can you please rebase now that getopt_compat is gone? |
|
@HJfod Ping? |
|
Oh sorry, didn't notice this! I merged master to my fork and it compiled succesfully (although the docs action seems to have failed). Will also be testing it in a bit! |
|
Nice! |

Clang on Windows without MSVC command line is a little bit quirky, so this PR adds support for it. I had an earlier PR (#886) for this too, but closed that one as I got too busy at the time to finish it. Now this works for the whole codebase as well as has CI tests for the new architechture combination.